<div class="layui-card-header layui-card">
    <span class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">首页</a>
        <a><cite>缓冲池列表</cite></a>
    </span>
</div>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">缓冲池列表</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-row" style="margin-bottom:15px;">
                    <div class="layui-form" style="float:right;">
                        <div class="layui-form-item" style="margin:0;">
                            <label class="layui-form-label">ID</label>
                            <div class="layui-input-inline">
                                <input type="text" name="channelMchId" id="channelMchId" autocomplete="off" class="layui-input">
                            </div>
                            <button id="search" class="layui-btn" data-type="reload">搜索</button>
                        </div>
                    </div>
                </div>
                <table id="hcList" lay-filter="hcList"></table>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="jeepayBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
    <!-- <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a> -->
    <!-- <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a> -->
</script>
    
<script>


    layui.use(['table','util','admin', 'form'], function(){
        var table = layui.table
        ,$ = layui.$
        ,form = layui.form
        ,admin = layui.admin
        ,element = layui.element;

        element.render('breadcrumb', 'breadcrumb');//渲染导航信息


        table.render({
            elem: '#hcList'
            ,url: layui.setter.baseUrl + '/bill/check_mistake_pool/list'
            ,where: {
                access_token: layui.data(layui.setter.tableName).access_token
            }
            ,id: 'tableReload'
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                    ,{field: 'channelMchId',title: '渠道商户ID'}
                    ,{field: 'batchNo',title: '对账批次号'}
                    ,{field: 'billDate', title: '账单时间', templet: '<div>{{ layui.util.toDateString(d.billDate, "yyyy-MM-dd") }}</div>' }
                    ,{field: 'bankType',title: '银行类型', template: '<div>{{ d.bankType == wxpay?"微信":"支付宝" }}</div>'}
                    ,{field: 'handleStatus',title: '类型状态', templet: '<div>{{ d.handleStatus == 0?"未处理":"已处理" }}</div>'}
                    ,{field:'createTime',  title: '创建时间', templet: '<div>{{ layui.util.toDateString(d.createTime) }}</div>' }
                    ,{field:'edite', title: '操作', toolbar: '#jeepayBar'  
                }
            ]]
            ,page: true
            ,skin: 'line'
        });





        //监听工具条
        table.on('tool(hcList)', function(obj){
            var data = obj.data;
            console.log(data)
            if(obj.event === 'detail'){
                location.href = layui.setter.baseLocal + "reconciliation/pool/detail/id=" + data.id;
            } 
        });

        // 事件处理
        var events = {
            del: function(othis, type){
                var checkStatus = table.checkStatus("tableReload")
                ,data = checkStatus.data; //获得选中的数据
                if(data.length === 0) return layer.msg('请选择数据');
                layer.confirm('确定删除选中的数据吗？', function(){
                    var userIds = "";
                    $.each(data, function(i, n){
                        userIds = userIds + "," + n.id;
                    });
                    console.log("userIds");
                    if(userIds != "") {
                        userIds = userIds.substring(1);
                    }
                    admin.req({
                        url: layui.setter.baseUrl + '/sys/message/delete', 
                        data: {ids: userIds}, 
                        success: function(){
                            layer.msg('删除成功', {
                                icon: 1
                            });
                            table.reload("tableReload"); //刷新表格
                        }
                    });
                });
            }
        };
            // 搜索
        var $ = layui.$, active = {
            reload: function(){
                var channelMchId = $('#channelMchId').val();
                //执行重载
                table.reload('tableReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        channelMchId: channelMchId,
                    }
                });
            }
        };
        $('#search').on('click', function() {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


        $('.dele').on('click', function(){
            var othis = $(this)
                    ,thisEvent = othis.data('events')
                    ,type = othis.data('type');
            events[thisEvent] && events[thisEvent].call(this, othis, type);
        });
        // 渲染表单
        form.render();


    })
</script>